package com.dk.controller;

import com.dk.api.WarAPI;
import com.dk.em.Result;
import com.dk.em.ResultEnum;
import com.dk.pojo.Warehouse;
import com.dk.pojo.WmMaterialStock;
import com.dk.service.MaterialStockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("stock")
@RefreshScope      //热更新
@Api(tags = "库存现有量")
public class MaterialStockController {

    @Autowired
    private MaterialStockService materialStockService;

    @Autowired
    private WarAPI warAPI;

    /*查询*/
    @ApiOperation("通过仓库id去查询这个仓库下的物料入库信息")
    @GetMapping                      //需要指定仓库  去查询这个仓库中的入库信息
    public Result getMaterStock(@RequestParam Integer warId) {
        /*根据状态去查询,状态为0的就是正常入库的,状态为1的就是退货的   条件仓库  状态  */
        Result<Warehouse> result = warAPI.getwarById(warId);
        if (result.getData() == null) {
            return Result.ZHRESPONSE(ResultEnum.NO_WAREHOUSE);//没有这个仓库
        }
        List<WmMaterialStock> materialStocks = materialStockService.getMaterStock(result.getData().getwId());
        if (materialStocks.size()==0){//这里
            return Result.ZHRESPONSE(ResultEnum.GOODS_SALES_RETURN);//已退货或者未入库
        }
        return Result.OK().setData(materialStocks);
    }// FIXME: 2023/5/11 当查询一个存在的仓库时这条数据已经退货  返回的时空数组  如何提示？ 还是就让他为空？   已经搞定
}
